/**
 * 
 */
package com.swg.cocobox.filetransfer.data;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author satriaprayoga
 *
 */
public class TransferRequest implements Serializable{
	
	private static final long serialVersionUID = 3605029496244188904L;
	
	private InetAddress destAddress;
	private int port;
	private File requestedFile;
	
	public void setDestAddress(InetAddress destAddress) {
		this.destAddress = destAddress;
	}
	
	public InetAddress getDestAddress() {
		return destAddress;
	}
	
	public void setRequestedFile(File requestedFile) {
		this.requestedFile = requestedFile;
	}
	
	public File getRequestedFile() {
		return requestedFile;
	}
	
	public void setPort(int port) {
		this.port = port;
	}
	
	public int getPort() {
		return port;
	}
	
	public byte[] sinkData() throws IOException{
		FileInputStream input=null;
		FileChannel channel=null;
		int numRead=0;
		input=new FileInputStream(requestedFile);
		channel=input.getChannel();
		ByteBuffer buffer=ByteBuffer.allocate((int)channel.size());
		buffer.clear();
		numRead=channel.read(buffer);
		
		byte[] data=new byte[numRead];
		System.arraycopy(buffer.array(), 0, data, 0, numRead);
		channel.close();
		input.close();
		return data;
	}
	
	
}
